import axios from "axios";

axios.defaults.baseURL = "http://localhost:8080/v1";
axios.defaults.timeout = 50000;
axios.defaults.withCredentials = false;
axios.defaults.headers.post['Content-Type'] = 'application/json';

export interface ResponseData<T> {
    code: string
    msg: string
    data: T
}

export interface ResponsePage<T> {
    page: number;
    size: number;
    total: number;
    content: T
}

const httpGet = async <T, E>(url: string, param?: E): Promise<T> => {
    const {data} = await axios.get<T>(url, {params: param})
    return data
}

const httpPost = async <T, E>(url: string, param: E): Promise<T> => {
    const {data} = await axios.post<T>(url, param)
    return data
}

const httpDelete = async <T, E>(url: string, param: E): Promise<T> => {
    const {data} = await axios.delete(url, {params: param})
    return data
}

export {httpGet, httpPost, httpDelete}
